package com.example.mall.auth.svc.constants;

import com.example.mall.common.constants.BaseEnum;
import com.example.mall.common.constants.CodeEnum;
import com.example.mall.common.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

/**
 * @author Mickey
 * @since 2022/4/10
 **/
@Getter
@AllArgsConstructor
public enum GrantType implements BaseEnum<GrantType> {

    PASSWD(0,"用户名密码登陆"),
    WECHAT(1,"微信登陆"),
    ;

    private final Integer code;
    private final String name;

    public static GrantType of(Integer code) {
        return Optional.ofNullable(BaseEnum.parseByCode(GrantType.class, code)).orElseThrow(() -> new BizException(CodeEnum.FAIL));
    }
}
